package com.aaa.controller;


import com.aaa.entity.Permission;
import com.aaa.security.util.WebUtils;
import com.aaa.service.PermissionService;
import com.aaa.util.JwtUtil;
import com.aaa.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("system/permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @GetMapping("getPermissionByEmpId/{id}")
    public List<Permission> getPermissionByUserid(@PathVariable Integer id){
         return permissionService.selectPermissionByEmpId(id);
    }
    //e_message

    @GetMapping("/gettoken")
    public Result getToken(){
        String token = WebUtils.getRequest().getHeader("token");
        Map<String, Object> tokenChaim = JwtUtil.getTokenChaim(token);
        String username = tokenChaim.get("username").toString();
        System.out.println("username = " + username);
        List<Permission> gettoken = permissionService.gettoken(username);
        return new Result(2000,"查询成功",gettoken);
    }
}
